<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<%@ page import="org.biojava.services.das.dao.Role" %>
<%@ page import="java.util.Date" %>
<%@page import="java.util.Scanner"%>
<%@ include file="sangerheader.jsp" %>

<%-- if  ( ! isAdmin ) {
	session.setAttribute("message","only administrators can view the memorytest.jsp page");
	response.sendRedirect("login.jsp");	
	return;
} else { --%>


<% String title="memory test";
   String header=title;
%>




<div id="main">


<% 
if(!isAdmin){
	response.sendRedirect("login.jsp");
}

HttpSession userSession = request.getSession(false);
     

	String action = request.getParameter("action");
	if (( action != null) && action.equals("invalidate")){
		if(userSession!=null) {               
			// 	userSession.invalidate();
		   	session.invalidate();
			
	       } else {
	    	   out.print("no session found");
	       }
	}

	userSession = request.getSession(true);
       
       
    Date date = new Date(userSession.getCreationTime());
    %>
    <p>
    Session ID: <strong><%=userSession.getId()%></strong> <br/>
    created at: <%=date %>
    </p>
    <% 
    int size = 1048576;

    long heapSize = Runtime.getRuntime().totalMemory() / size;
    
    // Get maximum size of heap in bytes. The heap cannot grow beyond this size.
    // Any attempt will result in an OutOfMemoryException.
    long heapMaxSize = Runtime.getRuntime().maxMemory() / size;
    
    // Get amount of free memory within the heap in bytes. This size will increase
    // after garbage collection and decrease as new objects are created.
    long heapFreeSize = Runtime.getRuntime().freeMemory() / size;

%>

<form action="memorytest.jsp" method="get">
<input type="hidden" name="action" value="invalidate"/>
<input type="submit" value="invalidate session"/>

</form>

<h2>Hostname</h2>
<pre>
<%
	StringBuffer sb = new StringBuffer();
	String cmd = "hostname";
	Process proc = Runtime.getRuntime().exec(cmd);
	Scanner s = new Scanner(proc.getInputStream());
    while(s.hasNextLine()) {
        sb.append(s.nextLine());
    }
    String result = sb.toString();
    out.print(result);

%>
</pre>

<h2>Memory</h2>
<pre>
    The request serverName = <%= request.getServerName() %>
    The request serverPort = <%= request.getServerPort() %>

    You are: <%= request.getRemoteAddr() %>

    memory
    	total: <%= heapSize %> M
	max  : <%= heapMaxSize %> M
	free : <%= heapFreeSize %> M

    The request method is <%= request.getMethod() %>
    The request URI is <%= request.getRequestURI() %>
    The request protocol is <%= request.getProtocol() %>
    The browser is <%= request.getHeader("user-agent") %>
</pre>

<h2>Headers:</h2>
    <pre>

<%
        java.util.Enumeration names = request.getHeaderNames();
        while (names.hasMoreElements()) {
            String name = (String)names.nextElement();
            out.println(name+": "+request.getHeader(name));
        }
    %>
</pre>

<h2>Java</h2>
<pre>
Java version: <%= System.getProperty("java.version")%>
Java vendor:  <%= System.getProperty("java.vendor")%>
Java home:    <%= System.getProperty("java.home")%>
Os.arch:      <%= System.getProperty("os.arch")%>
Os.name:      <%= System.getProperty("os.name")%>  
Os.version:   <%= System.getProperty("os.version")%>  
</pre>


<%-- } --%>

<%@ include file="sangerfooter.jsp" %>
